package com.bases {
	import com.bases.cellItem.BaseRadioCellItem;
	import com.Event.RadioSelectEvent;
	import com.Interface.IItem;
	import com.Interface.IRadioData;
	import com.Interface.ITRadioCellRender;
	import flash.events.MouseEvent;
	import flash.text.TextFormat;

	public class TRadioCellRender extends BaseRadioCellItem {
		protected var text:TLable;

		public function TRadioCellRender(){
			super();
			this.text = new TLable();
			this.addChild(text);
			this.relayout();
		}

		public function set radioText(value:String):void {
			this.text.text = value;
			this.adaptWidth();
		}

		override protected function relayout():void {
			super.relayout();
			//this.setSize(120,20); 
			this.radio.y = 5;
			this.text.setPos(20, 0);
			this.text.setSize(10, 25);
		}

		public function setFontSize(size:uint, color:uint = 0x000000):void {
			var font:TextFormat = new TextFormat(null, size, color);
			this.text.setTextFormat(font);
		}

		public function setFormat(format:TextFormat):void {
			this.text.setTextFormat(format);
		}

		public function setLableSize(w:Number, h:Number):void {
			this.text.setSize(w, h);
			this.radio.y = this.text.height / 3;
		}

		public function setLabelPos(x:Number, y:Number):void {
			this.text.setPos(x, y);
		}

		override public function set userData(value:*):void {
			super.userData = value;
			this.text.text = (value as IRadioData).getText();
			this.setFontSize(12);
			this.adaptWidth();
		}

		private function adaptWidth():void {
			if (this.text.textWidth > this.text.width){
				this.text.setSize(this.text.textWidth + 15, 30);
			}
			this.text.wordWrap = true;
		}

		/**
		 * 设置列表项的大小
		 * @param w 宽度
		 * @param h 高度
		 *
		 */
		override public function setSize(w:Number, h:Number):void {
			this.text.setSize(w - this.text.x, h);
		}
	}
}